﻿using Dyao.Book.Core;

namespace Foundation.Core
{
    public class SelectCollectionParameterTypeValueProviderRegistrar
    {
        public static readonly SelectCollectionParameterTypeValueProviderRegistrar Default = new SelectCollectionParameterTypeValueProviderRegistrar();

        Dictionary<Type, Type> _typeMappings = new Dictionary<Type, Type>();

        public SelectCollectionParameterTypeValueProviderRegistrar()
        {
            Add<CurrentUserSelectParameterValueProvider>(typeof(ICurrentUser)); //当前用户
        }

        public void Add<TValueProvider>(Type type)
            where TValueProvider : class, ISelectParameterValueProvider
        {
            _typeMappings[type] = typeof(TValueProvider);
        }

        public Type FindValueProvider(Type type)
        {
            _typeMappings.TryGetValue(type, out var providerType);

            return providerType;
        }
    }
}
